package com.zjw.zy.datasource.database;

import androidx.room.Database;
import androidx.room.Room;
import androidx.room.RoomDatabase;

import com.zjw.zy.bean.MemorandumItem;
import com.zjw.zy.bean.RecorderItem;
import com.zjw.zy.bean.Tip;
import com.zjw.zy.bean.WsMessage;
import com.zjw.zy.datasource.dao.MemorandumDao;
import com.zjw.zy.datasource.dao.RecorderDao;
import com.zjw.zy.datasource.dao.TipsDao;
import com.zjw.zy.datasource.dao.WechatMessageDao;
import com.zjw.zy.utils.AppUtils;

/**
 * @author ：zhong.jw
 * @date ：Created in 2022/9/30 9:12
 */

@Database(entities = {MemorandumItem.class, RecorderItem.class, Tip.class, WsMessage.class}, version = 1)
public abstract class AppDataBase extends RoomDatabase {

    private static final String TAG = "AppDataBase";

    private static volatile AppDataBase sAppDataBase;

    private static final String DATA_NAME = "AppData";

    //单例模式
    public static AppDataBase getInstance() {
        if (sAppDataBase == null) {
            synchronized (AppDataBase.class) {
                if (sAppDataBase == null) {
                    //构造者模式
                    sAppDataBase = Room.databaseBuilder(
                            AppUtils.getApp(),
                            AppDataBase.class,//自动生成impl
                            DATA_NAME
                    ).build();//build之前可以传入回调，在创建数据库前做点什么
                }
            }
        }
        return sAppDataBase;
    }

    public abstract MemorandumDao memorandumDao();

    public abstract RecorderDao recorderDao();

    public abstract TipsDao tipsDao();

    public abstract WechatMessageDao wechatMessageDao();
}
